Skip to content

port(wasm): Resolve __data_end and __heap_base as linker data addresses#2188

Merged
lapla-cogito merged 4 commits into
wild-linker:mainfrom
lapla-cogito:dataheap
Jul 9, 2026
Merged

port(wasm): Resolve __data_end and __heap_base as linker data addresses#2188
lapla-cogito merged 4 commits into
wild-linker:mainfrom
lapla-cogito:dataheap

Conversation

@lapla-cogito

Copy link
Copy Markdown
Member

Clang references these as undefined data symbols with MEMORY_ADDR relocations, not as globals. Assign absolute addresses after static data layout (data_end, and data_end plus the reserved stack gap for heap_base) and grow memory when the stack gap is required.

Part of #1431

@lapla-cogito lapla-cogito changed the title Resolve __data_end and __heap_base as linker data addresses port(wasm): Resolve __data_end and __heap_base as linker data addresses Jul 8, 2026
Comment thread libwild/src/wasm.rs
data_end: u32,
) -> Result<Option<LinkerDefinedDataAddress>> {
match name {
b"__data_end" => Ok(Some(LinkerDefinedDataAddress {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to previous PRs, the matching on symbol names makes me wary. It feels potentially wasteful and like it ideally shouldn't be necessary. Fine for now, but longer-term it'd be good to consider alternatives.

Comment thread wild/tests/sources/wasm/data-end-heap-base/data-end-heap-base2.c
Comment thread libwild/src/wasm.rs
.ok_or_else(|| crate::error!("Wasm __heap_base address overflow"))?;
Ok(Some(LinkerDefinedDataAddress {
address,
needs_stack_gap: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it about __heap_base that means it needs stack gap? Could be good to document that here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I get it. I guess in the ELF parts of our linker, symbols like __heap_base would be attached to the start/end of sections, one of those sections would be the stack and memory addresses would just be computed by adding sizes.

Comment thread libwild/src/wasm.rs
.ok_or_else(|| crate::error!("Wasm __heap_base address overflow"))?;
Ok(Some(LinkerDefinedDataAddress {
address,
needs_stack_gap: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I get it. I guess in the ELF parts of our linker, symbols like __heap_base would be attached to the start/end of sections, one of those sections would be the stack and memory addresses would just be computed by adding sizes.

Comment thread libwild/src/wasm.rs
@lapla-cogito lapla-cogito merged commit 4d9a006 into wild-linker:main Jul 9, 2026
22 checks passed
@lapla-cogito lapla-cogito deleted the dataheap branch July 9, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants